<!--
	Group Project - submit Rating/Comments to DB
	Dan Newman
	Nathan Nishimoto
	Al Husain
	3/11/2010
	uses: review_results.php, review_JS.js
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <script src="../mainJS.js" type="text/javascript"></script>

  <head>
    <title>Free Software Downloads - User Registration</title>
    <meta http-equiv="Content-Language" content="English" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="author" content="David Herreman (www.free-css-templates.com)" />
    <meta name="description" content="Free Css Template" />
    <meta name="keywords" content="free,css,template" />
    <meta name="Robots" content="index,follow" />
    <meta name="Generator" content="sNews 1.5" />
    <link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
  </head>
  <body>
    <?php
		session_start();
		include_once ("User_data.php");

      // assign form values to variables

      $userLogin = (isset($_POST['userLogin'])) ? trim($_POST['userLogin']) : '';
      $userPassword = (isset($_POST['userPassword'])) ? trim($_POST['userPassword']) : '';
      $firstName = (isset($_POST['firstName'])) ? trim($_POST['firstName']) : '';
      $middleName = (isset($_POST['middleName'])) ? trim($_POST['middleName']) : '';
      $lastName = (isset($_POST['lastName'])) ? trim($_POST['lastName']) : '';
      $country = (isset($_POST['country'])) ? trim($_POST['country']) : '';


      // if the form was submitted

      if (isset($_POST['submit']))
      {
          // check whether the username already exists

          $result = findDuplicateUser($userLogin);
          
          $duplicate = 0;
          if(isset($result)){
            extract ($result[0]);
            $duplicate = $dupUser;
          }

          if ($duplicate > 0)
          {
              $msg = '<p><font size="3" color="black" style="position:relative; left: 250px; top: 20px;"><strong>Please choose a different Username</strong></font></p>';
          }
          else
          {
              // insert new record

              addUser($userLogin, $userPassword, $firstName, $lastName, $middleName,  $country);

              //redirect user to login page
              $msg = '<p><font size="3" color="black" style="position:relative; left: 250px; top: 20px;"><strong>Thank you for Registering.  You will now be redirected to the login page.</strong></font></p>';
              header('Refresh: 2; URL=loginform.php');
          }
      }
	  ?>

    <div class="content">
      <div id="top">
        <h1>Free Software Downloads</h1>
        <h2>Freeware software</h2>
      </div>
      <!-- end of the Top part -->
    </div>

    <div id="prec2">
      <div id="wrap2">
        <div id="picReview">
          <div id="addReview">
            <form name ="addUserForm" id="addUserForm" action="user_registration.php" method="post" onsubmit="return checkForm(this)">

              <h2 style="text-align: center; color:white;">New User Registration</h2>

              <table align="center" style="font-size: large; color: white;">
                <tr>
                  <td>
                    Username:
                  </td>
                  <td>
                    <input type="text" name="userLogin" size="50" maxlength="20"
                               value="<?php echo $userLogin; ?>" onFocus="this.select()" />
                  </td>
                </tr>
                <tr>
                  <td>
                    Password:
                  </td>
                  <td>
                    <input type="password" name="userPassword" size="50" maxlength="20"
                            value="<?php echo $userPassword; ?>" onFocus="this.select()" />
                  </td>
                </tr>
                <tr>
                  <td>
                    First Name:
                  </td>
                  <td>
                    <input type="text" name="firstName" size="50" maxlength="20"
                            value="<?php echo $firstName; ?>" onFocus="this.select()" />
                  </td>
                </tr>
                <tr>
                  <td>
                    Last Name:
                  </td>
                  <td>
                    <input type="text" name="lastName" size="50" maxlength="20"
                            value="<?php echo $lastName; ?>" onFocus="this.select()" />
                  </td>
                </tr>
                <tr>
                  <td>
                    Middle Name:
                  </td>
                  <td>
                    <input type="text" name="middleName" size="50" maxlength="100"
                            value="<?php echo $middlename; ?>" onFocus="this.select()" />
                  </td>
                </tr>
                <tr>
                  <td>
                    Country:
                  </td>
                  <td>
                    <input type="text" name="country" size="50" maxlength="50"
                            value="<?php echo $country; ?>" onFocus="this.select()" />
                  </td>
                </tr>
                <tr>
                  <td>

                  </td>
                </tr>

                <tr>
                  <td colspan="2" align="center">
                    <input type="submit" name="submit" value="Register" />
                  </td>
                </tr>
              </table>

            </form>
          </div>
        </div>
      </div>
      <?php
          if (!empty($msg))
          {
            echo $msg;
          }
      ?>
      <div  id="addMenu">
        <a href="../index.php" title="home">
          <font size="3">Back to Home Page</font>
        </a>
      </div>
    </div>

    <div id="footer">
      <div class="right">
        &copy; Copyright 2010, Group Project CIS410 - <a href="/rss/">RSS Feed</a><br />Design: <a href="http://www.free-css-templates.com">David Herreman</a>
      </div>
      <a href="http://validator.w3.org/check?uri=referer" title="Validate">XHTML</a> - <a href="http://jigsaw.w3.org/css-validator/check/referer" title="Validate">CSS</a>
    </div>
  </body>

</html>
<?php


// if the user chose a duplicate username, display error

if (!empty($error))
{
    echo '<div id="error">' . $error . '</div>';
}
?>
<?php
echo "<mm:dwdrfml documentRoot=" . __FILE__ .">";$included_files = get_included_files();foreach ($included_files as $filename) { echo "<mm:IncludeFile path=" . $filename . " />"; } echo "</mm:dwdrfml>";
?>